#include<iostream>
#include<queue>
using namespace std;
const int MAXN =  1000007;
int n,k;

int vis[MAXN];
typedef struct Node{
	int n;
	int step;
}node;
void bfs(int n){
	queue<node> q;
	node head;
	head.n = n;
	head.step = 0;
	q.push(head);
	while(!q.empty()){
		head = q.front();
		q.pop();
		if(head.n == k){
			cout << head.step << "\n";
			return ;
		}
		for(int i = 1;i <= 3;i++){
			node next;
			if(i == 1) next.n = head.n + 1;
			if(i == 2) next.n = head.n - 1;
			if(i == 3) next.n = head.n * 2;
			if(next.n < 0 || next.n > MAXN) continue;
			if(!vis[next.n]){
				vis[next.n] = 1;
				next.step = head.step + 1;
				q.push(next);
			}
		}
	}
}

int main(){
	
	cin >> n >> k;
	bfs(n);
	
}